import { defineStore } from 'pinia';

export const STORE_KEY_USER = 'store-user';

export type User = {
  username: string;
  nickname: string;
};

export type UserState = {
  user?: User;
};

export const useUserStore = defineStore(STORE_KEY_USER, () => {
  const user = ref();

  const isAnonymous = computed((): boolean => {
    return !user.value;
  });

  const nickname = computed((): string => {
    const user_ = user.value;
    return !user_ ? '' : user_.nickname;
  });

  return { user, nickname, isAnonymous };
});
